function clientmsg(t) {
    var o = JSON.parse(t);
    $.ajax({
        url: "http://uc.taotaosou.com/clientAutoLogin?uid=" + o.uid + "&sig=" + o.sig,
        dataType: "json",
        success: function(t) {
            var o = {
                status: 1,
                id: t.user.id,
                nick: t.user.nick
            };
            chrome.browserAction.setBadgeText({
                text: ""
            }),
            chrome.browserAction.setBadgeBackgroundColor({
                color: "#ff0000"
            }),
            chrome.browserAction.setIcon({
                path: "../img/icon.png"
            }),
            chrome.browserAction.setPopup({
                popup: "html/popup.html"
            }),
            localStorage.setItem("TK-user-data", JSON.stringify(o))
        }
    })
}
function sentClientData(t) {
    try {
        var o = document.getElementById("taotaosouplugin");
        o && o.sendDatatoClient(t)
    } catch(e) {
        console.log(e)
    }
}
var taotaosou = {
    extension: {
        config: {}
    }
};
taotaosou.extension.config.data = {},
taotaosou.extension.config.randomGuid = function() {
    return "00000000xxxxyxxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,
    function(t) {
        var o = 16 * Math.random() | 0,
        e = "x" == t ? o: 3 & o | 8;
        return e.toString(16)
    }).toUpperCase()
},
taotaosou.extension.config.getQudao = function() {
    return "undefined" == typeof extinfo.qudao ? "0001009920131018": extinfo.qudao
},
taotaosou.extension.config.getSource = function() {
    return "undefined" == typeof extinfo.source ? "Unknow": extinfo.source
},
taotaosou.extension.config.getType = function() {
    return "undefined" == typeof extinfo.type ? "Cj_instal_tts": extinfo.type
},
taotaosou.extension.config.getVersion = function() {
    return "undefined" == typeof extinfo.version ? "2.1.3": extinfo.version
},
taotaosou.extension.config.getBrowser = function() {
    return "undefined" == typeof extinfo.browser ? "unknow": extinfo.browser
},
taotaosou.extension.config.getGuid = function() {
    return "undefined" == typeof extinfo.guid ? taotaosou.extension.config.randomGuid() : extinfo.guid
},
taotaosou.extension.config.init = function() {
    taotaosou.extension.config.data.version = taotaosou.extension.config.getVersion(),
    taotaosou.extension.config.data.qdid = taotaosou.extension.config.getQudao(),
    taotaosou.extension.config.data.source = taotaosou.extension.config.getSource(),
    taotaosou.extension.config.data.guid = taotaosou.extension.config.getGuid(),
    taotaosou.extension.config.data.actived = !1,
    taotaosou.extension.config.data.browser = taotaosou.extension.config.getBrowser(),
    taotaosou.extension.config.data.silent = !1,
    taotaosou.extension.config.data.type = taotaosou.extension.config.getType();
    try {
        if (null == document.getElementById("taotaosouplugin")) {
            var t = document.createElement("embed");
            t.setAttribute("type", "application/x-taotaosou-extension"),
            t.setAttribute("hidden", !0),
            t.setAttribute("id", "taotaosouplugin"),
            document.body.appendChild(t)
        }
    } catch(o) {
        console.log(o)
    }
},
taotaosou.extension.config.readLocalData = function() {
    try {
        var t = document.getElementById("taotaosouplugin");
        if (t) {
            var o = t.getQdid();
            "Unknow" != o && (taotaosou.extension.config.data.qdid = o),
            taotaosou.extension.config.data.actived = t.isActive(taotaosou.extension.config.data.type),
            taotaosou.extension.config.data.browser = t.getBrowser(),
            o = t.getGuid(),
            "Unknow" != o && (taotaosou.extension.config.data.guid = o),
            o = t.isSilentInstall(),
            "undefined" != typeof o && (taotaosou.extension.config.data.silent = o)
        }
    } catch(e) {
        console.log(e)
    }
},
taotaosou.extension.config.isNeedMsg = function() {
    var t = 1;
    try {
        var o = document.getElementById("taotaosouplugin");
        if (o) {
            var e = o.isNeedMsg();
            e || (t = "0")
        }
    } catch(n) {
        console.log(n)
    }
    return t
},
taotaosou.extension.config.getClientUseId = function() {
    var t = "NoLogin";
    try {
        var o = document.getElementById("taotaosouplugin");
        o && (t = o.getClientUserID())
    } catch(e) {
        console.log(e)
    }
    return t
},
taotaosou.extension.requestHandler = function(t, o, e) {
    if ("cmdInject" == t.command) {
        var n = JSON.parse(localStorage.tts_config_data);
        n.needmessage = taotaosou.extension.config.isNeedMsg(),
        e(n)
    }
},
taotaosou.extension.getOSFromUseragent = function() {
    var t = "Unknow";
    try {
        var o = window.navigator.userAgent,
        e = o.match(/([^(]+?)(?=\))/g);
        null != e && (t = e[0])
    } catch(n) {
        console.log(n)
    }
    return t
},
function() {
    var t = localStorage.tts_chrome_isActive;
    if (t = "undefined" == typeof t ? !1 : JSON.parse(t), taotaosou.extension.config.init(), t) {
        var o = localStorage.tts_config_data;
        "undefined" != typeof o && (o = JSON.parse(o)),
        "undefined" == typeof o || "undefined" == typeof o.actived ? (taotaosou.extension.config.readLocalData(), localStorage.tts_config_data = JSON.stringify(taotaosou.extension.config.data)) : null != o && null != o.version && o.version != taotaosou.extension.config.data.version && (taotaosou.extension.config.readLocalData(), o.version = taotaosou.extension.config.data.version, o.browser = taotaosou.extension.config.data.browser, o.source = taotaosou.extension.config.data.source, localStorage.tts_config_data = JSON.stringify(o), taotaosou.extension.config.data = o)
    } else taotaosou.extension.config.readLocalData(),
    localStorage.tts_config_data = JSON.stringify(taotaosou.extension.config.data),
    t = taotaosou.extension.config.data.actived,
    localStorage.tts_chrome_isActive = !0;
    chrome.extension.onRequest.addListener(taotaosou.extension.requestHandler),
    $.isEmptyObject = function(t) {
        for (var o in t) return ! 1;
        return ! 0
    },
    t || (taotaosou.extension.config.data.silent || chrome.tabs.create({
        url: "http://tk.taotaosou.com/newbie.html?id=2",
        selected: !0
    }), $.ajax({
        url: "http://log.ttsunion.com/install_statistics.do?type=" + taotaosou.extension.config.data.type + "&id=" + taotaosou.extension.config.data.qdid
    }))
} (),
function() {
    var t = function() {
        var t = new Date,
        o = (t.getYear() + 1900).toString();
        o += t.getMonth() + 1 > 9 ? (t.getMonth() + 1).toString() : "0" + (t.getMonth() + 1).toString(),
        o += t.getDate() > 9 ? t.getDate().toString() : "0" + t.getDate().toString();
        var e = localStorage.tts_lasttime_sendstartlog;
        return localStorage.tts_lasttime_sendstartlog = o,
        e && e == o ? !0 : !1
    };
    if (!t() && null == document.getElementById("extFirstStartLog")) try {
        var o = document.createElement("div");
        o.id = "extFirstStartLog";
        var e = document.createElement("img");
        e.src = "http://dc.log1.taotaosou.com/statistics.do?systemName=ttk_plugin_load&url=1&browser=" + taotaosou.extension.config.data.source + "&os=" + encodeURIComponent(taotaosou.extension.getOSFromUseragent()) + "&qdid=" + taotaosou.extension.config.data.qdid + "&guid=" + taotaosou.extension.config.data.guid + "&ver=" + taotaosou.extension.config.data.version + "&t=" + localStorage.tts_lasttime_sendstartlog,
        e.width = "0",
        e.height = "0",
        e.setAttribute("style", "display: none;"),
        o.appendChild(e),
        document.body.appendChild(o)
    } catch(n) {
        console.log(n)
    }
} (),
function(t, o) {
    var e = function() {
        this.init(),
        this.tkData = {
            status: 0,
            id: "",
            nick: ""
        }
    };
    o(document).ready(function() {
        new e
    }),
    e.prototype.init = function() {
        this.init_user()
    },
    e.prototype.init_user = function() {
        var t = this;
        t.init_bg()
    },
    e.prototype.init_bg = function() {
        var t = this;
        o.ajax({
            url: "http://uc.taotaosou.com/isLogin",
            dataType: "json",
            success: function(t) {
                var e;
                if (0 === t.status) {
                    e = {
                        status: t.status,
                        id: "",
                        nick: ""
                    },
                    chrome.browserAction.setPopup({
                        popup: ""
                    }),
                    chrome.browserAction.setBadgeText({
                        text: "?"
                    }),
                    chrome.browserAction.setBadgeBackgroundColor({
                        color: "#ff0000"
                    }),
                    chrome.browserAction.setIcon({
                        path: "../img/icon.png"
                    });
                    try {
                        var n = taotaosou.extension.config.getClientUseId();
                        if ("NoLogin" === n) o.ajax({
                            url: "http://uc.taotaosou.com/createtmpuser?tmpuserid=" + taotaosou.extension.config.data.guid,
                            dataType: "json",
                            success: function(t) {
                                e.id = t.id,
                                e.tip = 0,
                                localStorage.setItem("TK-user-data", JSON.stringify(e)),
                                localStorage.setItem("tmpuserid", t.id)
                            }
                        });
                        else {
                            var a = JSON.parse(n);
                            o.ajax({
                                url: "http://uc.taotaosou.com/clientAutoLogin?uid=" + a.uid + "&sig=" + a.sig,
                                dataType: "json",
                                success: function(t) {
                                    var o = {
                                        status: 1,
                                        id: t.user.id,
                                        nick: t.user.nick
                                    };
                                    chrome.browserAction.setBadgeText({
                                        text: ""
                                    }),
                                    chrome.browserAction.setBadgeBackgroundColor({
                                        color: "#ff0000"
                                    }),
                                    chrome.browserAction.setIcon({
                                        path: "../img/icon.png"
                                    }),
                                    chrome.browserAction.setPopup({
                                        popup: "html/popup.html"
                                    }),
                                    localStorage.setItem("TK-user-data", JSON.stringify(o))
                                }
                            })
                        }
                    } catch(i) {
                        console.log(i)
                    }
                } else e = {
                    status: t.status,
                    id: t.user.id,
                    nick: t.user.nick
                },
                chrome.browserAction.setBadgeText({
                    text: ""
                }),
                chrome.browserAction.setBadgeBackgroundColor({
                    color: "#ff0000"
                }),
                chrome.browserAction.setIcon({
                    path: "../img/icon.png"
                }),
                chrome.browserAction.setPopup({
                    popup: "html/popup.html"
                }),
                localStorage.setItem("TK-user-data", JSON.stringify(e)),
                sentClientData(JSON.stringify({
                    status: e.status,
                    bower: taotaosou.extension.config.data.source,
                    uid: e.id
                }))
            }
        }),
        t.tkData = JSON.parse(localStorage.getItem("TK-user-data")),
        chrome.browserAction.onClicked.addListener(function() {
            t.updataIcon()
        })
    },
    e.prototype.updataIcon = function() {
        var t = new RegExp(/^http:.*$/),
        e = localStorage.getItem("TK-user-data");
        chrome.browserAction.setPopup({
            popup: ""
        }),
        o.ajax({
            url: "http://log.taotaosou.com/browser_statistics.do?type=drawer_icon_click&t=" + (new Date).getTime()
        });
        try {
            e && 0 != JSON.parse(e).status ? (chrome.browserAction.setBadgeBackgroundColor({
                color: "#ff0000"
            }), chrome.browserAction.setPopup({
                popup: "html/popup.html"
            })) : chrome.tabs.getSelected(null,
            function(o) {
                t.test(o.url) ? chrome.tabs.executeScript(null, {
                    file: "js/login/login.js"
                }) : chrome.tabs.create({
                    url: "http://tk.taotaosou.com"
                },
                function() {
                    chrome.tabs.executeScript(null, {
                        file: "js/login/login.js"
                    })
                })
            })
        } catch(n) {
            console.log(n)
        }
    },
    chrome.cookies.onChanged.addListener(function(t) {
        if (t.cause.match(/overwrite/) && t.removed) {
            var o = localStorage.getItem("tmpuserid");
            "tts_userId" === t.cookie.name && (chrome.browserAction.setPopup({
                popup: ""
            }), chrome.browserAction.setBadgeText({
                text: "?"
            }), chrome.browserAction.setBadgeBackgroundColor({
                color: "#ff0000"
            }), chrome.browserAction.setIcon({
                path: "../img/icon.png"
            }), localStorage.setItem("TK-user-data", JSON.stringify({
                command: "cmdUpdateState",
                status: 0,
                id: o
            })))
        } else t.cause.match(/explicit/) && !t.removed && "tts_userId" === t.cookie.name && (chrome.browserAction.setBadgeText({
            text: ""
        }), chrome.browserAction.setBadgeBackgroundColor({
            color: "#ff0000"
        }), chrome.browserAction.setIcon({
            path: "../img/icon.png"
        }), chrome.browserAction.setPopup({
            popup: "html/popup.html"
        }), localStorage.setItem("TK-user-data", JSON.stringify({
            command: "cmdUpdateState",
            status: 1,
            id: t.cookie.value
        })), sentClientData(JSON.stringify({
            status: 1,
            bower: taotaosou.extension.config.data.source,
            uid: t.cookie.value
        })))
    }),
    chrome.runtime.onConnect.addListener(function(t) {
        t && "userStatus" == t.name && t.postMessage(localStorage.getItem("TK-user-data"))
    })
} (window, jQuery);